package com.merry.mq.exchange.direct;

import com.merry.mq.utils.RabbitMQUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 处理info
 */
public class ReceiveLogDirect02 {

    public static String EXCHANGE_NAME ="direct_logs";

    public static void main(String[] args) throws IOException, TimeoutException {
        Channel channel = RabbitMQUtils.getChannel();
        //声明一个direct交换机
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        //声明一个队列,并绑定它
        channel.queueDeclare("desk",false,false,false,null);
        channel.queueBind("desk",EXCHANGE_NAME,"info");

        //接收消息
        DeliverCallback deliverCallback = (consumerTag,message)->{
            System.out.println("02 info处理。"+new String(message.getBody()));

            channel.basicAck(message.getEnvelope().getDeliveryTag(),false);
        };

        channel.basicConsume("desk",false,deliverCallback,(consumerTag)->{
            System.out.println("消息消费失败！");
        });
    }
}
